public class Whiles {

	private Condition condition;
	private Statements stmtSeq;
	
	public Whiles(Tokens tokens) {
		this.parse(tokens);
	}
	
	public void parse(Tokens tokens) {
		// check for "while"
		if(tokens.getToken() != 8){
			System.err.println("Keyword \"while\" expected before token: " + tokens.idName());
			System.exit(0);
		}
		tokens.skipToken();
		this.condition = new Condition(tokens);
		// check for "loop"
		if(tokens.getToken() != 9){
			System.err.println("Keyword \"loop\" expected before token: " + tokens.idName());
			System.exit(0);
		}
		tokens.skipToken();
		this.stmtSeq = new Statements(tokens);
		// check for "end"
		if(tokens.getToken() != 3){
			System.err.println("Keyword \"end\" expected before token: " + tokens.idName());
			System.exit(0);
		}
		tokens.skipToken();
		// check for ";"
		if(tokens.getToken() != 12){
			System.err.println("Semicolon expected before token: " + tokens.idName());
			System.exit(0);
		}
		tokens.skipToken();
	}
	
	public void runLoop(){
		while(this.condition.runCond()){
			this.stmtSeq.runStmtSeq();
		}
	}
}